﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GeneralLibs;
using Lists;
using System.Linq;

namespace BasicForms
{
    public partial class DefaultLocalSettings : BasicForms.FrmOKCancel
    {
        public DefaultLocalSettings()
        {
            InitializeComponent();
        }

        private void DefaultLocalSettings_Load(object sender, EventArgs e)
        {
            if (DesignMode) return;
            #region cmbKho
            cmbKho.DisplayColumn = "Ten";
            cmbKho.ValueColumn = "ID";
            cmbKho.AddVisibleColumn("Ma", "Mã");
            cmbKho.AddVisibleColumn("Ten", "Tên");
            #endregion

            #region cmbThueSuat
            cmbThueSuat.DataSource = DanhMucThueSuat.Instance.DataView;
            cmbThueSuat.DisplayColumn = "Ten";
            cmbThueSuat.ValueColumn = "ID";
            cmbThueSuat.AddVisibleColumn("Ma", "Mã");
            cmbThueSuat.AddVisibleColumn("Ten", "Tên");
            #endregion

            
            cmbKho.EditValue = GeneralLibs.LocalSettings.HeThong.KhoID;
            cmbThueSuat.EditValue = GeneralLibs.LocalSettings.HeThong.ThueSuatID;
            cmbPhuongThucThanhToanMuaHang.EditValue = GeneralLibs.LocalSettings.HeThong.PhuongThucThanhToanMuaHangID;
            cmbPhuongThucThanhToanBanHang.EditValue = GeneralLibs.LocalSettings.HeThong.PhuongThucThanhToanBanHangID;
        }


        protected override void btnOK_Click(object sender, EventArgs e)
        {

            if (cmbKho.EditValue is Guid) GeneralLibs.LocalSettings.HeThong.KhoID = (Guid)cmbKho.EditValue;
            else GeneralLibs.LocalSettings.HeThong.KhoID = Guid.Empty;

            if(cmbThueSuat.EditValue is Guid)GeneralLibs.LocalSettings.HeThong.ThueSuatID = (Guid)cmbThueSuat.EditValue;
            else GeneralLibs.LocalSettings.HeThong.ThueSuatID = Guid.Empty;

            if (cmbPhuongThucThanhToanMuaHang.EditValue is Guid) GeneralLibs.LocalSettings.HeThong.PhuongThucThanhToanMuaHangID = (Guid)cmbPhuongThucThanhToanMuaHang.EditValue;
            else GeneralLibs.LocalSettings.HeThong.PhuongThucThanhToanMuaHangID = Guid.Empty;

            if (cmbPhuongThucThanhToanBanHang.EditValue is Guid) GeneralLibs.LocalSettings.HeThong.PhuongThucThanhToanBanHangID = (Guid)cmbPhuongThucThanhToanBanHang.EditValue;
            else GeneralLibs.LocalSettings.HeThong.PhuongThucThanhToanBanHangID = Guid.Empty;

            GeneralLibs.LocalSettings.HeThong.Save2File();

            Close();
        }
    }
}
